#if SERVER
using ActorSystem;
using GameDesigner;
using Net.Share;

namespace Example2
{
    public abstract partial class Actor : ActorBase<Actor, NormalProperty, SkillBase<Actor, BuffBase<Actor>>, BuffBase<Actor>>
    {
        public StateController controller;

        public override void AddOperation(in Operation opt)
        {
            currOpers.Add(opt);
        }

        public virtual void OnDamage(Actor target, int damage)
        {
            AddOperation(new Operation(Command.Damage, Identity) { index = damage });
        }

        public override void OnOperation(in Operation opt)
        {
            switch (opt.cmd)
            {
                case Command.SyncPosition:
                    SyncPosition(opt);
                    break;
                case Command.SwitchState:
                    SwitchState(opt);
                    break;
                case Command.Damage:
                    Damage(opt);
                    break;
            }
        }

        private void Damage(in Operation opt)
        {
            if (Scene.TryGetActor<Actor>(opt.target, out var actor))
            {
                if (actor == null)
                    return;
                Scene.TryGetActor<Actor>(opt.uid, out var target);
                actor.Damage(target, new DamageBuff() { Damage = 10 });
            }
        }

        private void SwitchState(in Operation opt)
        {
            AddOperation(opt);
        }

        private void SyncPosition(in Operation opt)
        {
            transform.SetPositionAndRotation(opt.position, opt.rotation);
        }
    }
}
#endif